package com.tsh.chat.service.impl;

import com.tsh.chat.domain.ChatHistory;
import com.tsh.chat.mapper.ChatHistoryMapper;
import com.tsh.chat.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatServiceImpl implements ChatService {
    @Autowired
    private ChatHistoryMapper chatHistoryMapper;

    @Override
    public List<ChatHistory> getChatHistoryByUserId(int userId) {
        return chatHistoryMapper.findByUserId(userId);
    }

    @Override
    public int deleteHistoryById(int userId){
        return chatHistoryMapper.deleteByUserId(userId);
    }

    @Override
    public int insertNewChat(int userId, String role,String content){
        ChatHistory chatHistory = new ChatHistory();
        chatHistory.setUser_id(userId);
        chatHistory.setRole(role);
        chatHistory.setContent(content);
        return chatHistoryMapper.insert(chatHistory);
    }
}
